package com.youngball.web.controller;

import CommandEntity.HardWare;
import com.syg.manager.service.scheduler.LightCtrlService;
import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiOperation;
import com.youngball.utill.Code;
import com.youngball.web.config.MyDefineException;
import com.youngball.web.webconfig.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by liaopingzhu on 2016/12/22.
 */
@Controller
@RequestMapping(value = "lightCtrl")
@ApiModel("灯控相关接口")
public class LightCtrlController extends BaseController {

    @Autowired
    private LightCtrlService lightCtrlService;

    private final static String CLIENTYPE = "http";

    @RequestMapping(value = "handleLight",method = RequestMethod.POST,headers = "Accept=application/json")
    @ApiOperation("灯控操作")
    public ResponseEntity<Map> handleLight(@RequestBody com.syg.manager.entity.LightCommand lightCommand){
        HardWare.LightRequest response;
        try {
            //设置是http调用
            lightCommand.setClienType(CLIENTYPE);
            response = lightCtrlService.handleLight(lightCommand);
            Map map = new HashMap();
            return bulidResult(response.getResultData());
//            if(lightCommand.getCmd() == 2) return bulidResult(lightCtrlService.String2Maps(response.getResultData()));
//            else return bulidResult(Code.SUC.getValue(), response.getResultMessage().toString(),HttpStatus.OK);
        }catch (MyDefineException e){
            return bulidResult(Code.DEFAI.getValue(),e.getMessage(),HttpStatus.OK);
        }catch (Exception e){
            return bulidResult(Code.DEFAI.getValue(),"操作灯控失败",HttpStatus.OK);
        }
    }

}
